package com.hzhr.iot.device.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.device.dao.CollectDeviceDao;
import com.hzhr.iot.device.entity.CollectDeviceEntity;
import com.hzhr.iot.device.queryModel.custom.CollectDeviceCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class RegulatorDeviceMaintenanceCardDaoHelper {
    @Autowired
    CollectDeviceDao collectDeviceDao;

    public CollectDeviceEntity getByCodeAndCompanyIdAndCategoryCode(String code, int companyId, String categoryCode) {
        if (StringUtils.isEmpty(code) || StringUtils.isEmpty(categoryCode)) return null;
        CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
        queryModel.setEqual_code(code);
        queryModel.setEqual_companyId(companyId);
        queryModel.setEqual_categoryCode(categoryCode);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        CollectDeviceEntity record = collectDeviceDao.selectEntity(queryModel);
        return record;
    }

    public CollectDeviceEntity getById(int id) {
        CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        CollectDeviceEntity record = collectDeviceDao.selectEntity(queryModel);
        return record;
    }

    public int getCountByCountAndCompanyIdAndCategoryCode(String code, int companyId, String categoryCode) {
        if (StringUtils.isEmpty(code) || StringUtils.isEmpty(categoryCode)) return 0;
        CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
        queryModel.setEqual_code(code);
        queryModel.setEqual_companyId(companyId);
        queryModel.setEqual_categoryCode(categoryCode);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = collectDeviceDao.selectCount(queryModel);
        return count;
    }

    public int getCountByCodeAndCompanyId(String code, int companyId) {
        if (StringUtils.isEmpty(code)) return 0;
        CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
        queryModel.setEqual_code(code);
        queryModel.setEqual_companyId(companyId);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = collectDeviceDao.selectCount(queryModel);
        return count;
    }
}
